<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>填写主题信息</span>
      </div>
      <el-form label-position="left" size="mini" label-width="80px" :model="formdata">
        <el-form-item label="法人姓名">
          <el-input v-model="formdata.person"></el-input>
        </el-form-item>
        <el-form-item label="企业名称">
          <el-input v-model="formdata.company"></el-input>
        </el-form-item>
        <el-form-item label="营业执照号">
          <el-input v-model="formdata.businessLicence"></el-input>
        </el-form-item>

        <el-form-item label="营业执照">
          <single-upload v-model="formdata.businessLicencePic"></single-upload>
        </el-form-item>

        <el-form-item label="法人身份证">
          <template>
            <single-upload v-model="formdata.identityPicFront"></single-upload>
            <single-upload v-model="formdata.identityPicBack"></single-upload>
          </template>
        </el-form-item>

        <el-form-item label="验证码">
          <el-input v-model="formdata.autoCode">
            <span slot="suffix" @click="handleGetAutoCode" style="margin-right: 15px">
              <label class="color-main">获取验证码</label>
            </span>
          </el-input>
        </el-form-item>
      </el-form>
    </el-card>

    <div style="padding: 30px,15px; margin-top: 60px; align=center">
      <el-button
        type="danger"
        style="width: 100%; height:44px"
        round
        :loading="loading"
        @click="onSubmit"
      >确认提交</el-button>
    </div>
  </div>
</template>

<script>
import singleUpload from "@/components/Upload/singleUpload";
import { shopUpdate } from "@/api/shop";
import { getAuthCode } from "@/api/login";

export default {
  components: { singleUpload },
  data() {
    return {
      loading: false,
      formdata: {
        person: "",
        company: "",
        businessLicence: "",
        businessLicencePic: "",
        identityPicFront: "",
        identityPicBack: "",
        identityType: 2,
        autoCode: null
      }
    };
  },
  methods: {
    onSubmit() {
      this.loading = true;
      shopUpdate(this.formdata)
        .then(response => {
          this.loading = false;
        })
        .catch(error => {
          this.loading = false;
        });
    },
    handleGetAutoCode() {
      this.autoLoading = true;
      getAuthCode(null).then(response => {
        this.formdata.autoCode = response.data;
        this.autoLoading = false;
      });
    }
  }
};
</script>